package com.david.http;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.util.EntityUtils;

public class ResponseHandler implements
		org.apache.http.client.ResponseHandler<HttpResult> {

	public HttpResult handleResponse(HttpResponse response)
			throws ClientProtocolException, IOException {

		StatusLine statusLine = response.getStatusLine();
		HttpResult ret = new HttpResult();
		ret.setStatus(statusLine.getStatusCode());
		ret.setHeaders(response.getAllHeaders());
		ret.setContent(response.getEntity() == null ? null : EntityUtils
				.toByteArray(response.getEntity()));
		return ret;
	}
}